package com.glory.hikvisionmobile.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.glory.hikvisionmobile.R;
import com.glory.hikvisionmobile.bean.TrackIn.XPdaEquipment;
import com.glory.hikvisionmobile.customView.HikLabelSpinner;

import java.util.ArrayList;
import java.util.List;

/**
 * *****************************
 *
 * @Anthor yazhou
 * @Email 1184545990@qq.com
 * @Time 2020/1/9 13:36
 * @DESC *****************************
 */
public class MainEquipmentSpinnerAdapter extends HikLabelSpinner.HikSpinnerAdapter<XPdaEquipment> {

    private XPdaEquipment empty;

    public MainEquipmentSpinnerAdapter(List<XPdaEquipment> xPdaEquipments) {
        super(xPdaEquipments);
        empty = new XPdaEquipment();
        empty.setEquipmentId(null);
        empty.setDescription("请选择主设备");
        if (xPdaEquipments == null) {
            xPdaEquipments = new ArrayList<>();
        }
        xPdaEquipments.add(0, empty);
        setData(xPdaEquipments);
    }

    @Override
    public int getDropDownViewId() {
        return R.layout.hik_item_spinner;
    }

    @Override
    public void bindDataDownView(int position, View itemView, XPdaEquipment data) {
        if (data.getEquipmentId().length() == 0) {
            ((TextView)itemView.findViewById(R.id.tv_label)).setTextColor(Color.parseColor("#9B9B9B"));
        } else {
            ((TextView)itemView.findViewById(R.id.tv_label)).setTextColor(Color.parseColor("#333333"));
        }
        ((TextView)itemView.findViewById(R.id.tv_label)).setText(data.getDescription());
    }

    @Override
    public int getViewId() {
        return R.layout.hik_spinner;
    }

    @Override
    public void bindDataView(int position, View itemView, XPdaEquipment data) {
        if (data.getEquipmentId().length() == 0) {
            ((TextView)itemView.findViewById(R.id.tv_label)).setTextColor(Color.parseColor("#9B9B9B"));
        } else {
            ((TextView)itemView.findViewById(R.id.tv_label)).setTextColor(Color.parseColor("#333333"));
        }
        ((TextView)itemView.findViewById(R.id.tv_label)).setText(data.getDescription());
    }

    @Override
    public void setData(List<XPdaEquipment> data) {
        if (getData() != null && !getData().equals(data)) {
            if (data == null) {
                data = new ArrayList<>();
            }
            data.add(0, empty);
        }
        super.setData(data);
    }
}
